Skip to content

[Main] - User encounters a "record is not open" error when attaching a document to a posted sales shipment in Dynamics 365 (Base Application v28). - #10160

Open
DhavalMore88 wants to merge 4 commits into
microsoft:mainfrom
DhavalMore88:bugs/Bug-646549-Main-User-encounters-a-record-is-not-open-error-when-attaching
Open

[Main] - User encounters a "record is not open" error when attaching a document to a posted sales shipment in Dynamics 365 (Base Application v28).#10160
DhavalMore88 wants to merge 4 commits into
microsoft:mainfrom
DhavalMore88:bugs/Bug-646549-Main-User-encounters-a-record-is-not-open-error-when-attaching

Conversation

@DhavalMore88

@DhavalMore88 DhavalMore88 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Bug 646549: [master] [All-E] [SME][SaaS] User encounters a "record is not open" error when attaching a document to a posted sales shipment in Dynamics 365 (Base Application v28).

AB#646549

Issue: When a user uploads a file from the Documents FactBox ("Doc. Attachment List Factbox", Page 1178) on a Posted Sales Shipment, the upload fails with the runtime error "The record is not open." The same happens on Posted Return Receipt, while the identical action works correctly on Sales Order, Purchase Order and Posted Sales Invoice. The AL call stack points to Table 1173 "Document Attachment".InsertAttachment / SaveAttachmentFromStream.

Cause: The GetRefTable procedure in DocumentAttachmentMgmt.Codeunit.al (Codeunit 1173) has a case DocumentAttachment."Table ID" statement with no branch for Database::"Sales Shipment Header" (110) or Database::"Return Receipt Header" (6661), even though both tables are already registered in TableHasNumberFieldPrimayKey. Because no branch matches, RecRef.Open() is never called, GetRefTable returns false, and the FactBox's AttachmentsUpload action ignored that result and passed the unopened RecordRef on to DocumentAttachment.SaveAttachment(files, RecRef), where RecRef.Find() in InsertAttachment throws "The record is not open."

Solution: Added the missing Database::"Sales Shipment Header" and Database::"Return Receipt Header" cases to GetRefTable, each opening the RecordRef on its table and calling GetTable when the posted document is found — matching the existing pattern used for Sales Invoice Header and Sales Cr.Memo Header. Additionally hardened all three GetRefTable call sites in DocAttachmentListFactbox.Page.al (Upload files, Show details, Attach from email) to raise a clear error when the source record still cannot be resolved after the OnAfterGetRecRefFail event, instead of letting an unopened RecordRef reach the platform and surface the cryptic message for any other unmapped table.

@github-actions github-actions Bot added From Fork Pull request is coming from a fork Integration GitHub request for Integration area Linked Issue is linked to a Azure Boards work item labels Aug 12, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Aug 12, 2026
@DhavalMore88
DhavalMore88 marked this pull request as ready for review August 13, 2026 12:31
@DhavalMore88
DhavalMore88 requested a review from a team August 13, 2026 12:31
Comment thread src/Layers/W1/Tests/Misc/DocumentAttachmentTests.Codeunit.al
@DhavalMore88 DhavalMore88 added the SCM GitHub request for SCM area label Aug 13, 2026
@github-actions github-actions Bot removed the SCM GitHub request for SCM area label Aug 13, 2026
@DhavalMore88
DhavalMore88 requested review from neeleshsinghal and removed request for neeleshsinghal August 14, 2026 12:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime failure when uploading document attachments from the Documents FactBox on posted Sales Shipments and Return Receipts by ensuring the underlying RecordRef is opened/resolved for those source tables, and by surfacing a clearer error when the source record cannot be resolved.

Changes:

  • Extend Document Attachment Mgmt.GetRefTable with missing mappings for Sales Shipment Header and Return Receipt Header.
  • Harden Doc. Attachment List Factbox actions (upload/show details/attach from email) to error explicitly when the source RecordRef remains unresolved after the failure event hook.
  • Add automated tests (W1 + ES layers) validating attachment upload succeeds for posted sales shipments and posted return receipts.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Layers/W1/Tests/Misc/DocumentAttachmentTests.Codeunit.al Adds coverage for uploading attachments on posted sales shipments/return receipts; includes helper setup for posting prerequisites.
src/Layers/W1/BaseApp/Foundation/Attachment/DocumentAttachmentMgmt.Codeunit.al Adds GetRefTable branches to open/resolve RecordRef for Sales Shipment Header and Return Receipt Header.
src/Layers/W1/BaseApp/Foundation/Attachment/DocAttachmentListFactbox.Page.al Prevents passing an unopened RecordRef to attachment save flows; raises a clearer “unsupported table” error if still unresolved.
src/Layers/ES/Tests/Misc/DocumentAttachmentTests.Codeunit.al Mirrors the W1 test additions for the ES test layer.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

From Fork Pull request is coming from a fork Integration GitHub request for Integration area Linked Issue is linked to a Azure Boards work item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants